package com.ttbj.product.salesman.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ttbj.api.dto.PermissionDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.salesman.PermissionService;
import com.ttbj.core.util.DtoTransitionUtils;
import com.ttbj.salesman.bean.po.Permission;
import com.ttbj.salesman.dao.PermissionMapper;


@Service("permissionService")
public class PermissioinServiceImpl implements PermissionService{
	
	@Autowired
	private PermissionMapper permissionMapper;
	
	@Override
	public List<PermissionDto> queryPermissionByRoleId(long roleId) throws BusinessException {
		List<Permission> permissions = permissionMapper.queryPermissionByRoleId(roleId);
        if (null != permissions && !permissions.isEmpty()) {
            List<PermissionDto> permissionDtos = new ArrayList<PermissionDto>();
            for (Permission perm : permissions) {
                permissionDtos.add((PermissionDto) DtoTransitionUtils.trans(PermissionDto.class, perm));
            }
            return permissionDtos;
        }
        return null;
	}

	@Override
	public List<PermissionDto> queryAll(Long roleId) throws BusinessException {
		List<Permission> permissions = permissionMapper.queryAll(roleId);
        if (null != permissions && !permissions.isEmpty()) {
            List<PermissionDto> permissionDtos = new ArrayList<PermissionDto>();
            for (Permission permission : permissions) {
                permissionDtos.add((PermissionDto) DtoTransitionUtils.trans(PermissionDto.class, permission));
            }
            return permissionDtos;
        }
        return null;
	}

	@Override
	public String queryString() throws BusinessException {
		String string = "测试数据。。。。。。。。。。。。。。。";
		return string;
	}

}
